#pragma once

//
class TbButton: public Window
{
   HDC hdc, memdc; int ind; HIMAGELIST iml, iml1, iml2; TRACKMOUSEEVENT tme;

public:

   int status; bool over;

   //
   TbButton(int i, HIMAGELIST* piml, HIMAGELIST* piml1, HIMAGELIST* piml2, TRACKMOUSEEVENT* ptme)
   { ind = i; iml = *piml; iml1 = *piml1; iml2 = *piml2; tme = *ptme; status = 0; over = false; }

   //
   int OnMouseMove(WPARAM, LPARAM)
   {
      if(status != 3 && !over)
      { tme.hwndTrack = hwnd; if(TrackMouseEvent(&tme)) { status = 1; over = true; Invalidate(); } }
      return 0;
   }

   //
   int OnMouseLeave() { if(status != 3) { status = 0; Invalidate(true); over = false; } return 0; }

   //
   int OnLButtonDown(WPARAM, LPARAM) { if(status == 1) { status = 2; Invalidate(); } return 0; }

   //
   int OnLButtonUp(WPARAM, LPARAM)
   {
      if(status == 2) switch(ind) //player
      {
      case 0:
         hpobj->SendMsgP(WM_COMMAND, 678, MAKELONG(0,0)); //open
         SendMsgP(WM_COMMAND, 345, MAKELONG(0,3));
         SendMsgP(WM_COMMAND, 345, MAKELONG(1,0));
         SendMsgP(WM_COMMAND, 345, MAKELONG(2,3));
         SendMsgP(WM_COMMAND, 345, MAKELONG(3,3));
         break;

      case 1:
         hpobj->SendMsgP(WM_COMMAND, 678, MAKELONG(1,0)); //play
         SendMsgP(WM_COMMAND, 345, MAKELONG(0,3));
         SendMsgP(WM_COMMAND, 345, MAKELONG(1,3));
         SendMsgP(WM_COMMAND, 345, MAKELONG(2,0));
         SendMsgP(WM_COMMAND, 345, MAKELONG(3,0));
         break;

      case 2:
         hpobj->SendMsgP(WM_COMMAND, 678, MAKELONG(2,0)); //pause
         SendMsgP(WM_COMMAND, 345, MAKELONG(0,3));
         SendMsgP(WM_COMMAND, 345, MAKELONG(1,0));
         SendMsgP(WM_COMMAND, 345, MAKELONG(2,3));
         SendMsgP(WM_COMMAND, 345, MAKELONG(3,0));
         break;

      case 3:
         hpobj->SendMsgP(WM_COMMAND, 678, MAKELONG(3,0)); //stop
         SendMsgP(WM_COMMAND, 345, MAKELONG(0,0));
         SendMsgP(WM_COMMAND, 345, MAKELONG(1,3));
         SendMsgP(WM_COMMAND, 345, MAKELONG(2,3));
         SendMsgP(WM_COMMAND, 345, MAKELONG(3,3));
         break;
      }

      over = false;

      return 0;
   }


   //
   int OnPaint(HDC hdc)
   {

      if(status == 0)
         DrawStateA(hdc, 0, 0, (LPARAM)ImageList_GetIcon(iml, ind, 0), 0, 0, 0, 24, 24, DST_ICON|DSS_NORMAL);
      else if(status == 1)
         DrawStateA(hdc, 0, 0, (LPARAM)ImageList_GetIcon(iml1, ind, 0), 0, 0, 0, 24, 24, DST_ICON|DSS_NORMAL);
      else if(status == 2)
         DrawStateA(hdc, 0, 0, (LPARAM)ImageList_GetIcon(iml2, ind, 0), 0, 0, 0, 24, 24, DST_ICON|DSS_NORMAL);
      else if(status == 3)
         DrawStateA(hdc, 0, 0, (LPARAM)ImageList_GetIcon(iml, ind, 0), 0, 0, 0, 24, 24, DST_ICON|DSS_NORMAL|DSS_DISABLED);

      ReleaseDC(hwnd, hdc);

      return 0;
   }


};
